public without sharing class AssignmentSaleDetailHandler {

	/*
    *
	   将kettle 里的数据 匹配客户和产品
    */
    public static void matchdata(List<AssignmentSaleDetail__c> list_new){

    	Set<String>codes = new Set<String>();
    	Set<String>accs = new Set<String>();

    	for (AssignmentSaleDetail__c sm  :list_new ) {
    		
    		if(sm.ProductPK__c != null)codes.add(sm.ProductPK__c);
    		if(sm.AccountPK__c != null)accs.add(sm.AccountPK__c);
    	}


    	//1.检索产品
    	Map<String,Id> proMap = new Map<String,Id>();
    	for (Product__c p : [select Id ,pk_invbasdoc__c from Product__c where pk_invbasdoc__c in:codes]) {
    		proMap.put(p.pk_invbasdoc__c ,p.Id);
    	}
    	//2.检索客户
    	Map<String,Id> accMap = new Map<String,Id>();
    	for (Account acc: [select Id , NCICCode__c from Account where NCICCode__c in:accs]) {
    		accMap.put(acc.NCICCode__c ,acc.Id);
    	}

    	
    	///3.匹配客户和产品
    	for (AssignmentSaleDetail__c sm  :list_new ) {
    		
    		if(accMap.containsKey(sm.AccountPK__c))sm.Account__c = accMap.get(sm.AccountPK__c);
    		if(proMap.containsKey(sm.ProductPK__c))sm.Product__c = proMap.get(sm.ProductPK__c);

    	}


    }
    
}